<!--
 * @Date: 2022-04-11 17:09:36
 * @Author: 陶子
 * @LastEditTime: 2022-07-12 11:29:33
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\warehouseManagement\inventoryQuery\SearchTag.vue
 * @pageName: 这是--(出入库查询——筛选)--页面
-->
<template>
  <div class="search-content wrap-apply" :style="{top: GLOBAL.currentEnvironment ? '0' : ''}" v-show="showSearchTag">
    <Search ref="topSearch" class="search" placeholder="物品编号|物品名称|库管单" :isAdd="false" :isScreen="false" :isType="false"></Search>
    <van-cell-group style="margin-top:0.1rem">
      <p class="label FormTit"><span></span>出入库类型</p>
      <van-field-select-picker :supportClear='true' label="" placeholder="请选择" v-model="filterForm.operateTaskType" :columns="statusList"
        :option="{ label: 'name', value: 'value' }" @confirm="selectProcess" @prePopShow="showAccountDialog" />
      <div class="bottomLine"></div>
    </van-cell-group>
    <van-cell-group>
      <p class="label FormTit"><span></span>出入库日期</p>
      <div :class="filterForm.planStartTimeArr?'haveUnitBox':''">
        <van-field :is-link='filterForm.planStartTimeArr?false:true' readonly name="picker" v-model="filterForm.planStartTimeArr" @click="planStart_beginTime = true"
          placeholder="请选择">
        </van-field>
        <img src="~@/assets/img/filedClear.png" v-if="filterForm.planStartTimeArr" alt="" @click.stop='clickEndClose' class="filedClear">
      </div>
      <!-- <van-field is-link readonly name="picker" v-model="filterForm.planStartTimeArr" @click="planStart_beginTime = true" placeholder="请选择">
      </van-field> -->
    </van-cell-group>
    <van-cell-group>
      <p class="label FormTit"><span></span>规格</p>
      <van-field v-model="filterForm.spec" placeholder="输入">
      </van-field>
    </van-cell-group>
    <div class="search-bottom">
      <span class="btncancel" @click="btnCancel">重置</span>
      <span class="btnconfirm" @click="btnConfirm">确定</span>
    </div>
    <!--计划开始时间—开始时间 -->
    <van-popup v-model="planStart_beginTime" position="bottom" :close-on-click-overlay='false'>
      <van-datetime-picker @confirm="confirmPlanStartBeginTime" v-model="componentStartTime" @cancel="cancelPlanStartBeginTime" type="date" title="开始时间"
        :formatter="formatter" />
    </van-popup>
    <!--计划开始时间—结束时间 -->
    <van-popup v-model="planStart_endTime" position="bottom" :close-on-click-overlay='false'>
      <van-datetime-picker @confirm="confirmPlanStartEndTime" @cancel="cancelPlanStartEndTime" type="date" title="结束时间" :min-date="startEndMinTIme"
        :formatter="formatter" />
    </van-popup>
  </div>
</template>

<script>
import ContactPickers from "@/components/choiceuse/ContactPickers";
import upload from "@/components/upload/upload";
import VanFieldSelectPicker from "@/components/ActionSheet/VanFieldSelectPicker";
import moment from "moment";
import Search from "@/components/search";
import { outAinApi } from "@/api/mobile";
export default {
  name: "search",
  components: { ContactPickers, upload, Search, VanFieldSelectPicker },
  data() {
    return {
      showSearchTag: false,
      planStart_beginTime: false,
      planStart_endTime: false,
      startEndMinTIme: new Date(2020, 1, 1),
      componentStartTime: new Date(),
      /***** */
      filterForm: {
        operateTaskType: null,
        planStartTimeArr: "",
      },
      statusList: [],
    };
  },
  computed: {},
  mounted() {},
  created() {
    this.getStatusList();
  },
  methods: {
    clickEndClose() {
      this.componentStartTime = new Date();
      this.filterForm.startDate = "";
      this.filterForm.endDate = "";
      this.filterForm.planStartTimeArr = "";
      this.$forceUpdate();
    },
    showModal(keyword, dropdownObj) {
      this.showSearchTag = true;
      this.$nextTick(() => {
        this.$refs.topSearch.value = keyword;
        this.filterForm = JSON.parse(JSON.stringify(dropdownObj));
      });
    },
    //显示弹框选择
    showAccountDialog() {},
    //选择任务工序的回调
    selectProcess(itemTaskType) {
      if (itemTaskType) {
        this.filterForm.operateTaskType = itemTaskType.value;
      } else {
        this.filterForm.operateTaskType = null;
      }
    },
    getStatusList() {
      let obj = {
        type: "",
      };
      outAinApi(obj).then((res) => {
        if (res.success) {
          this.statusList = res.result;
        } else {
          this.$toast(res.message);
        }
      });
    },
    // 选择计划开始时间—开始时间
    confirmPlanStartBeginTime(date) {
      this.startEndMinTIme = date;
      this.filterForm.startDate = moment(date).format("YYYY-MM-DD");
      this.filterForm.endDate = ""; // 切换开始时间后直接置空结束时间重新选择
      this.planStart_beginTime = false;
      this.planStart_endTime = true;
    },
    // 取消计划开始时间—开始时间
    cancelPlanStartBeginTime() {
      this.planStart_beginTime = false;
    },
    // 选择计划开始时间—结束时间
    confirmPlanStartEndTime(date) {
      this.filterForm.endDate = moment(date).format("YYYY-MM-DD");
      this.filterForm.planStartTimeArr =
        this.filterForm.startDate + "~" + this.filterForm.endDate;
      this.planStart_endTime = false;
    },
    // 取消计划开始时间—结束时间
    cancelPlanStartEndTime() {
      this.filterForm.startDate = "";
      this.componentStartTime = new Date();
      this.planStart_endTime = false;
    },

    formatter(type, val) {
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      if (type === "hour") {
        return val + "时";
      }
      if (type === "minute") {
        return val + "分";
      }
      return val;
    },

    btnCancel() {
      this.$refs.topSearch.value = "";
      this.filterForm = {
        operateTaskType: null,
      };
    },
    btnConfirm() {
      let sureObj = {
        ...this.filterForm,
        keyword: this.$refs.topSearch.value,
      };
      this.showSearchTag = false;
      this.$emit("getCategory", sureObj);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/theme.scss";
.search-content {
  //  padding-bottom: 0.5rem;
  position: fixed;
  top: 0.35rem;
  width: 100%;
  height: 100vh;
  background: #f5f5f5;
  z-index: 99;
  .formgroup {
    background: #ffffff;
    // padding: 0 0.16rem;
    margin-top: 0.1rem;
    margin-bottom: 0.2rem;
    padding-top: 0.1rem;

    .title {
      width: 0.58rem;
      height: 0.14rem;
      font-size: 0.15rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #191f25;
      line-height: 0.05rem;
      margin-left: 0.16rem;
    }
  }
  .search-bottom {
    width: 100%;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0.06rem 0.11rem;
    font-size: 0.16rem;
    font-weight: 500;
    .btncancel {
      flex: 1;
      background: #f6f6f6;
      border: 0.01rem solid rgba(25, 31, 37, 0.12);
      box-sizing: border-box;
      height: 0.39rem;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 0.03rem;
      margin-right: 0.11rem;
      color: #191f25;
    }
    .btnconfirm {
      flex: 1;
      background: #1890ff;
      box-sizing: border-box;
      height: 0.39rem;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 0.03rem;
      color: #ffffff;
    }
  }
}
.bottomLine {
  height: 0.01rem;
  background-color: #f0f0f0;
  margin: 0 0.16rem;
}
.haveUnitBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding-right: 0.16rem;
  /deep/ .van-cell {
    padding-right: 0;
    width: 2.6rem;
  }
  /deep/ .van-field__control {
    max-width: 3rem;
  }
}
</style>